﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RoomList.aspx.cs" Inherits="ZLDC.Estate.TM.RoomList" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>房号列表</title>
    <base target="_self" />
    <link href="../css/main.css" rel="stylesheet" type="text/css" />

    <script src="../js/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>

    <script src="../js/jquery/jquery.hiAlerts-min.js" type="text/javascript"></script>

    <script src="../js/LexunJS.js" type="text/javascript"></script>

    <script src="../js/jShowDiv.js" type="text/javascript"></script>

    <link href="../js/jquery/style/jquery.hiAlerts.css" rel="stylesheet" type="text/css" />
    <base  target="_self"/>
    <style type="text/css">
        ul
        {
            padding: 0;
            width: 520px; /*设置表格宽 */
            height: auto; /*设置表格高*/
            margin: 0px;
        }
        li
        {
            /*设置单元格边框*/
            list-style: none; /*清除项目列表前的标记*/
            float: left; /*设置单元格浮动，用于水平排列*/
            display: block; /*设置单元格为块级元素于用语控制大小等*/
            width: 100px; /*设置单元格宽*/
            height: auto; /*设置单元格高*/
            text-align: center; /*设置单元格内文本对齐方式*/
            margin: 1px;
        }
    </style>

    <script type="text/javascript">


        function RoomList() {
            var bid = LexunJS.GetQueryString("id");  // 楼盘ID
            $("#divList1").html("<img src=\"../images/loading.gif\" />"); // 清空列表 
            $.ajax({
                type: 'POST',
                url: '../Handler/HandlerRoomNo.ashx',
                data: 'act=SelectRoomNoList&bid=' + bid,
                timeout: '10000',
                error: function() {
                    alert("系统繁忙,请稍候后试！");
                }, success: function(json) {
                    listCallBack(json);
                }
            });

        }

        /*
        功能: 将返回的json数据进行排版
        json: json数据
        */

        function listCallBack(response) {            
            var json = eval("(" + response + ")");
            var record = json.record;

            if (record == null || record.length == 0) {                
                $("#divList1").html("<font color='red'>&nbsp;系统内暂无您查询的信息!</font>"); 
                return;
            }

            // 权限判断
            var hCompetencesIsEdit = $("#hCompetencesIsEdit").val();                // 0不允许修改 1允许修改
            var hCompetencesIsDel = $("#hCompetencesIsDel").val();                  // 0不允许删除 1允许删除
            var hCompetencesIsOtherName = $("#hCompetencesIsOtherName").val();      // 0不允许申请别名 1允许申请别名   

            var arr = [];
            arr.push("<table id='table1' width='100%' border='0' cellpadding='0' cellspacing='1' bgcolor='#a8c7ce'>");
            arr.push("<tr>");
            arr.push("<td height='25' width='30px' bgcolor='d3eaef' class='STYLE6'>");
            arr.push("楼层");
            arr.push("</td>");
            arr.push("<td height='25' width='30px' bgcolor='d3eaef' class='STYLE6'>");
            arr.push("用途");
            arr.push("</td>");
            arr.push("<td height='25' bgcolor='d3eaef' class='STYLE6'>");
            arr.push("房号");
            arr.push("</td>");
            arr.push("</tr>");

            var recordLength = record.length;
            var floor1 = -9999;
            var floor2 = 0;
            for (var i = 0; i < recordLength; i++) {
                floor2 = record[i].floor;

                if (floor1 != floor2) {
                    if (floor1 != -9999) {
                        arr.push("</ul>");
                        arr.push("</td>");
                        arr.push("</tr>");
                    }
                    floor1 = floor2
                    if (i % 2 == 0)
                        arr.push("<tr id='tr_" + record[i].id + "' bgcolor='#FFFFFF'>");
                    else
                        arr.push("<tr id='tr_" + record[i].id + "' bgcolor='#EEEDED'>");

                    arr.push("<td height='20' class='STYLE6'>");
                    arr.push(floor2);
                    arr.push("</td>");
                    arr.push("<td height='20' class='STYLE6'>");

                    var useValue = "";
                    var useStr = record[i].usage;
                    if (useStr == "1")
                        useValue = "住宅";
                    else if (useStr == "2")
                        useValue = "商铺";
                    else if (useStr == "3")
                        useValue = "写字楼";
                    else if (useStr == "4")
                        useValue = "商住";
                    else if (useStr == "5")
                        useValue = "仓库";
                    else if (useStr == "6")
                        useValue = "厂房";
                    else if (useStr == "7")
                        useValue = "地皮";
                    else if (useStr == "8")
                        useValue = "项目盘";
                    else if (useStr == "9")
                        useValue = "其他*";
                    else
                        useValue = useStr;
                    arr.push(useValue);    
                    arr.push("</td>");
                    arr.push("<td height='20' class='STYLE6'>");
                    arr.push("<ul>");
                }

                if (record[i].bstatus == 1) {
                    arr.push("<li  style = 'background:#FF99FF' >");
                }
                else if (record[i].bstatus == 2) {
                    arr.push("<li style = 'background:Yellow' >");
                }
                else if (record[i].bstatus == 3) {
                    arr.push("<li style = 'background:#66CCFF' >");
                }
                else {
                    arr.push("<li>");
                }
                if(record[i].othername != "")
                    arr.push("<div title='" + record[i].name + record[i].othername + "'>" + record[i].name + "(<font color='red'>" + record[i].othername.substring(0, 8) + "</font>)");
                else
                    arr.push("<div title='" + record[i].name + "'>" + record[i].name);

                if (hCompetencesIsDel == 1)
                    arr.push("<input type='checkbox' name='checkbox_" + record[i].id + "' id='" + record[i].id + "' onclick='cbSelect(this, " + record[i].id + ")' />&nbsp;");
                
                if (record[i].isvalid == 1)
                    arr.push("<div  style='color:blue;'>待审核");                
                arr.push("</div>");    
                
                // 权限判断
                if (hCompetencesIsEdit == 1)
                    arr.push("<a href=\"javascript:ShowDialog('RoomNo.aspx','Update','" + record[i].id + "','" + record[i].bid + "');\" value='" + record[i].id + "' style='color:red'  href='' >修改</a>&nbsp;");
                if (hCompetencesIsDel == 1)
                    arr.push("<a href=\"javascript:DeleteName(" + record[i].id + ");\" value='" + record[i].name + "' style='color:red;'>删除</a>&nbsp;");
                if (hCompetencesIsOtherName == 1)
                    arr.push("<a href=\"javascript:add('" + record[i].id + "');\" value='" + record[i].name + "' style='color:red;' >别名</a>");
                arr.push("</li>");
            }
            arr.push("</table>");
            $("#divList1").html(arr.join('')); // 显示列表
        }

        function ShowDialog(url, type, value, id) {
            var path = url + "?Type=" + type + "&value=" + value + "&bid=" + id;
            var parameter = "";
            var style = "dialogWidth:534px; dialogHeight:400px; status:0;scroll:1; help:0; resizable:1;Scrollbars=yes,Toolbar=no,Location=no,Direction=no,Resizeable=no";
            window.showModalDialog(path, parameter, style);
            
            RoomList();
           
        }

        function DeleteName(id) {
            hiConfirm("您确定要删除该行，请谨慎操作！", "确认框", function(result) {
                if (result) {
                    $.ajax({
                        type: 'POST',
                        url: '../Handler/HandlerRoomNo.ashx',
                        data: 'act=del&id=' + id,
                        timeout: '10000',
                        error: function() {
                            alert("系统繁忙，请稍候后试！");
                        },
                        success: function(json) {
                            showDetailCallBack(json);
                        }
                    });
                }
            });
        }

        // 批量删除除
        function delAll() {
            var idlist = document.getElementById("hID").value;
            if (idlist == "") {
                alert("请先选择您要删除的房号！");                
                return false;
            }
            
            hiConfirm("您确定要删除这些房号，请谨慎操作！", "确认框", function(result) {
                if (result) {
                    $.ajax({
                        type: 'POST',
                        url: '../Handler/HandlerRoomNo.ashx',
                        data: 'act=delAll&idlist=' + idlist,
                        timeout: '10000',
                        error: function() {
                            alert("系统繁忙，请稍候后试！");
                        },
                        success: function(json) {
                            showDetailCallBack(json);
                        }
                    });
                }
            });
        }
        
        function showDetailCallBack(response) {
            var json = eval("(" + response + ")");
            if (json > 0) {
                RoomList();
            } else {
                alert("删除失败！");
            }
        }

        //房间号ID
        var rid = 0;
        function add(id) {
            rid = id;
            openLayer("divList1", "divLayer");

        }
        //申请房间号
        function UpdateOtherName() {
            //楼盘名称
            var name = document.getElementById("iOtherName").value;
            if (name.length = 0 || name.replace(/(^\s*)|(\s*$)/g, "") == "") {
                alert("别名不能为空！");
                document.getElementById("iOtherName").focus();
                return false;
            }

            var tname = 't_roomno';
            //申请类型
            var type = 3;
            var cName = document.getElementById("iUserName").value;
            var cDept = document.getElementById("iUserDept").value;
            var cDId = document.getElementById("ideptid").value;
            $.ajax({
                type: 'POST',
                url: '../Handler/HandlerRoomNo.ashx',
                data: 'act=UR&id=' + rid + '&name=' + name + '&type=' + type + '&tname=' + tname + '&cName=' + cName + '&Cdept=' + cDept + '&cDId=' + cDId,
                timeout: '10000',
                error: function() {
                    alert("修改失败！");
                }, success: function(json) {
                    Success(json);
                }
            });
        }

        function Success(response) {
            var json = eval("(" + response + ")");
            if (json > 0) {
                closeLayer();
            } else {
                alert("申请失败！");
            }
        }

        function roomNoDialog(id) {
            var width = 600;
            var height = 350;
            var iframe = "<iframe id=\"iframe_" + id + "\"  width=\"" + width + "\" height=\"" + (height - 30) + "\" frameborder=\"0\" scrolling=\"no\" src=\"RoomNo.aspx?id=" + id + "\" />";
            var title = "添加房号";

            dialog(iframe, title, width, height);
        }

        // 单选
        function cbSelect(obj, objvalue) {
            if (obj.checked) {
                LexunJS.addOrCutData(1, "hID", objvalue);
            }
            else {
                LexunJS.addOrCutData(0, "hID", objvalue);
            }
        }

        // 全选
        function cbSelectAll() {
            document.getElementById("hID").value = "";
            var cbAll = document.getElementById("checkboxAll");
            var checkList = document.getElementsByTagName("input");

            if (cbAll.checked) {
                for (var i = 0; i < checkList.length; i++) {
                    if (checkList[i].type == "checkbox") {
                        checkList[i].checked = true;
                        if (parseInt(checkList[i].id) > 0) LexunJS.addOrCutData(1, "hID", checkList[i].id);
                    }
                }
            }
            else {
                for (var i = 0; i < checkList.length; i++) {
                    if (checkList[i].type == "checkbox") {
                        checkList[i].checked = false;
                        if (parseInt(checkList[i].id) > 0) LexunJS.addOrCutData(0, "hID", checkList[i].id);
                    }
                }
            }
        }
   
    </script>

</head>
<body onload="RoomList();">
    <input id="iUserName" runat="server" type="hidden" />
    <input id="iUserDept" runat="server" type="hidden" />
    <input id="ideptid" runat="server" type="hidden" />
    <div style="text-align: center;">
        <asp:Literal ID="ltDiv" runat="server"></asp:Literal>
    </div>
    <div id='divList1'>
    </div>
    <!--修改-->
    <div id="divLayer" style="display: none; background: none repeat scroll 0% 0% rgb(255, 255, 255);
        width: 350px; height: 160px;">
        <h1 id="popup_title">
            修改</h1>
        <em id="ctl"></em><em id="cbl"></em><em id="ctr"></em><em id="cbr"></em>
        <div id="tabcontent" style="text-align: center; margin-left: 20px; margin-right: 20px;">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td>
                        房号别名：
                    </td>
                    <td>
                        <input id="iOtherName" name="iOtherName" value="" type="text" style="width: 200px" />
                    </td>
                </tr>
            </table>
        </div>
        <div id="tabbottom" style="text-align: right;">
            <input id="btnOk" class="button_bak" type="button" value="确定" onclick="UpdateOtherName()" />
            <input id="btnReturn" class="button_bak" type="button" value="返回" onclick="closeLayer()" />
        </div>
    </div>
    <input id="hCompetencesIsAdd" name="hCompetencesIsAdd" value="0" type="hidden" runat="server" /><!-- 0不允许添加栋阁 1允许添加栋阁 -->
    <input id="hCompetencesIsEdit" name="hCompetencesIsEdit" value="0" type="hidden"
        runat="server" /><!-- 0不允许修改 1允许修改 -->
    <input id="hCompetencesIsDel" name="hCompetencesIsDel" value="0" type="hidden" runat="server" />
    <input id="hCompetencesIsOtherName" name="hCompetencesIsOtherName" value="0" type="hidden"
        runat="server" /><!-- 0不允许申请别名 1允许申请别名 -->
    <input id="hID" name="hID" value="" type="hidden" />        
</body>
</html>
